<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function Promise(executor){

        this.PromiseState='pending';
        this.PromiseResult=null;

        const self=this;

        //成功回调函数
        function resolve(data){
            self.PromiseState='fulfilled';
            self.PromiseResult=data;
        }
        //失败回调函数
        function reject(data){
            self.PromiseState='rejected';
            self.PromiseResult=data;
        }


        //捕捉异常
        try {
            //同步调用 执行器函数
            executor(resolve, reject);
        } catch (e) {
            reject(e)
        }
    }

    Promise.prototype.then=function (onResolved,onRejected){

    }


    let p=new Promise(function (resolve,reject){
        resolve('ok')
    });

    console.log(p)

    let p2=new Promise(function (resolve,reject){
       throw 'error';
    });

    console.log(p2)


</script>
</body>
</html>